package result

import (
	"github.com/gin-gonic/gin"
	nhttp "net/http"
)

func JsonResult(c *gin.Context, data interface{}, e error) {
	httpCode := nhttp.StatusOK
	var code uint = 1
	var msg string = "success"

	if e != nil {
		code = 0
		msg = e.Error()
		httpCode = nhttp.StatusInternalServerError
	}

	if data == nil {
		data = struct{}{}
	}

	c.JSON(httpCode, gin.H{
		"code": code,
		"msg":  msg,
		"data": data,
	})
}
